import { ApiCall } from "tsrpc";
import { ReqLogined, ResLogined } from "../../../tsrpc/shared/protocols/gate/PtlLogined";
import { gs } from "../../../GateServiceEntra";
import { CommonFactory } from "../../../module/common/CommonFactory";

export default async function (call: ApiCall<ReqLogined, ResLogined>) {
    // TODO
    // call.error('API Not Implemented');

    const ret = await gs.GateModel.hcAccount.callApi(`Logined`, {
        account: call.req.account,
        password: call.req.password
    })

    if (ret.isSucc) {
        //需要登录到大厅服务端
        call.succ({
            __ssoToken:ret.res.__ssoToken,
            uid: ret.res.uid
        })
        // const isEnter = await gs.enterHall(call.req.addr, ret.res.__ssoToken);
        // if (isEnter) {
        //     call.succ({
        //         __ssoToken: ret.res.__ssoToken,
        //         uid: ret.res.uid
        //     })
        // } else {
        //     call.error("无法登录大厅", {code:"ENTER_HALL_FAILURE"});
        // }
    }else {
        call.error(ret.err);
    }
}